"""
应用程序配置设置
"""
from typing import List, Optional
from pydantic import Field
from pydantic_settings import BaseSettings


class Settings(BaseSettings):
    """应用程序设置"""
    
    # 应用基础配置
    app_name: str = "客货装备信息管理追踪监控平台"
    version: str = "0.1.0"
    debug: bool = Field(default=False, env="DEBUG")
    log_level: str = Field(default="INFO", env="LOG_LEVEL")
    
    # 数据库配置
    database_url: str = Field(env="DATABASE_URL")
    test_database_url: Optional[str] = Field(default=None, env="TEST_DATABASE_URL")
    
    # Redis配置
    redis_url: str = Field(default="redis://localhost:6379/0", env="REDIS_URL")
    
    # JWT配置
    secret_key: str = Field(env="SECRET_KEY")
    algorithm: str = Field(default="HS256", env="ALGORITHM")
    access_token_expire_minutes: int = Field(default=30, env="ACCESS_TOKEN_EXPIRE_MINUTES")
    
    # Celery配置
    celery_broker_url: str = Field(default="redis://localhost:6379/1", env="CELERY_BROKER_URL")
    celery_result_backend: str = Field(default="redis://localhost:6379/2", env="CELERY_RESULT_BACKEND")
    
    # CORS配置
    cors_origins: List[str] = Field(
        default=["http://localhost:3000", "http://localhost:8080"],
        env="CORS_ORIGINS"
    )
    
    # 加密配置
    encryption_key: str = Field(env="ENCRYPTION_KEY")
    
    # WebSocket配置
    websocket_host: str = Field(default="0.0.0.0", env="WEBSOCKET_HOST")
    websocket_port: int = Field(default=8001, env="WEBSOCKET_PORT")
    
    class Config:
        env_file = ".env"
        case_sensitive = False


# 全局设置实例
settings = Settings()
